package com.bxd.baodan.adapter;

import java.util.List;

import com.bxd.baodan.R;
import com.bxd.baodan.activity.QuestionDetailActivity;
import com.bxd.baodan.item.SimilarQuestionsItem;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MyGVQuestionDetaiAdapter extends BaseAdapter{
	private Context context;
	private LayoutInflater inflater;
	private List<SimilarQuestionsItem> list;
	public MyGVQuestionDetaiAdapter(Context context,List<SimilarQuestionsItem> list){
		this.context=context;
		this.list=list;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if(convertView == null){
			convertView = inflater.inflate(
					R.layout.mygv_question_item, null);
			holder = new ViewHolder();
			holder.tv_titel=(TextView)convertView.findViewById(R.id.tv_titel);
			holder.relative_title=(RelativeLayout)convertView.findViewById(R.id.relative_title);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv_titel.setText(list.get(arg0).getQ_title());
		holder.relative_title.setTag(arg0);
		holder.relative_title.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(context,
						QuestionDetailActivity.class);
				intent.putExtra("qid", list.get(Integer.parseInt(arg0.getTag().toString())).getQ_id());
				context.startActivity(intent);
				((Activity) context).overridePendingTransition(R.anim.slide_in_right,
						R.anim.slide_out_left);
			}
		});
		return convertView;
	}
	
	class ViewHolder {
		TextView tv_titel;
		RelativeLayout relative_title;
	}


}
